package com.whp.yky.yky.controller;


import com.auth0.jwt.interfaces.DecodedJWT;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.whp.yky.yky.entity.Process;
import com.whp.yky.yky.entity.Storeroom;
import com.whp.yky.yky.entity.poentity.Document;
import com.whp.yky.yky.response.ResponseData;
import com.whp.yky.yky.service.impl.StoreroomServiceImpl;
import com.whp.yky.yky.utils.JwtUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author whp
 * @since 2021-03-12
 */
@RestController
@CrossOrigin
public class StoreroomController {

    @Autowired
    private StoreroomServiceImpl storeroomService;

    @ApiOperation(value="获取所有档案信息", notes="获取所有档案信息")
    @PostMapping("/getStoreroomInfo")
    public ResponseData getStoreroomInfo(@RequestBody Storeroom storeroom, @RequestParam Integer pageNum, @RequestParam Integer pageSize){
        ResponseData res = new ResponseData();
        res.setCode(20000);
        IPage<Storeroom> pageList = this.storeroomService.getStoreroomInfo(new Page( (long)pageNum,(long)pageSize),storeroom);
        res.setData(pageList);
//        res.setTotal(documentServiceImpl.getDocumentInfo(document).size());

        return res;

    }

    @PostMapping("/updateStoreroomInfo")
    public ResponseData updateStoreroomInfo(@RequestBody Storeroom storeroom){


        boolean result = false;
        ResponseData res = new ResponseData();


        if(storeroom.getId()== null){
            result= storeroomService.insertStoreroomInfo(storeroom);
        }else{
            result= storeroomService.updateStoreroomInfo(storeroom);
        }

        if (result){
            res.setCode(20000);
            res.setData("success");

        }else{
            res.setCode(50000);
            res.setData("fail");
        }
        return res;
    }

    @DeleteMapping("/deleteStoreroomInfo/{id}")
    public ResponseData deleteStoreroomInfo( @PathVariable("id") int id){
        ResponseData res = new ResponseData();
        boolean result = storeroomService.removeById(id);
        if (result){
            res.setCode(20000);
            res.setData("success");

        }else{
            res.setCode(50000);
            res.setData("fail");
        }
        return res;

    }

}

